<?php defined('BASEPATH') OR exit('No direct script access allowed');
require APPPATH.'/libraries/REST_Controller.php';

class useraddress extends REST_Controller
{     
	function get_user_address_by_id_get()
	{
		if(!$this->get('user_id')) {
			$this->response(array('status'=>"false",
					'message' => 'user_id not provided'), 200);
		}
		$this->load->model('useraddressdao');
		$success = $this->useraddressdao->getbyid($this->get('user_id'));
		$this->response(array('user address'=>$success,'status'=> $success ? 'true' : 'false'), 200);
	}

	function get_user_addresses_get()
	{
		$this->load->model('useraddressdao');
		$success = $this->useraddressdao->get_all();
		$this->response(array('user addresses'=>$success,'status'=> $success ? 'true' : 'false'), 200);
	}	
	
	function insert_put()
	{
		if(!$this->put('user_id') || !$this->put('street_id') ||
		 !$this->put('remaining_address') || !$this->put('user_branch_phone'))
		{
			$this->response(NULL, 400);
		}
		$this->load->model('useraddressdao');
		$address = $this->useraddressdao->insert(
				$this->put('user_id'),
				$this->put('street_id'),
				$this->put('remaining_address'),
				$this->put('user_branch_phone')
				);
		$this->response($address,200);
		if($address == 0){
			$this->response(array('user address'=>$address,'status'=> 'true'), 200); // 200 being the HTTP response code
		} else {
			$this->response(array('status'=>"false"), 200); // 200 being the HTTP response code
		}
	}
}
?>